home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / rjs.lha / RJS / String / src / io.C < prev    next >
C/C++ Source or Header  |  1991-06-14  |  715b  |  41 lines

  1. #include <ctype.h>
  2.  
  3. #include "String.h"
  4. #include <iomanip.h>
  5.  
  6. ostream &operator<<(ostream &os,const RJS_String &s) {
  7.     os.write(s.cptr(),s.length());
  8.     return os;
  9. }
  10.  
  11. int getline(istream &is, RJS_String &s, char delim, int dropit)
  12. {
  13. int ch;
  14. // should check for errors on is first
  15.  
  16.   s="";
  17.  
  18.   while ( ((ch = is.get()) != EOF) && (ch != delim)) s+=char(ch);
  19.  
  20.   if (ch==delim && !dropit) s+=delim;
  21.  
  22.   return s.length();
  23.  
  24. }
  25.  
  26. istream &operator>>(istream &is, RJS_String &s) 
  27. {
  28. // should check for errors on is first
  29.   int ch;
  30.   s="";
  31.  
  32.   while ( ((ch = is.get()) != EOF) && (isspace(ch))) ; // spin
  33.  
  34.   if (ch!=EOF) {
  35.     s+=char(ch);
  36.         while ( ((ch = is.get()) != EOF) && (!isspace(ch))) s+=char(ch);
  37.   }
  38.  
  39.   return is;
  40. }
  41.